﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace Cloak.Mvp.Autofac
{
	/// <summary>
	/// Binds a keyed presenter type to a view class
	/// </summary>
	public class KeyedPresenterAttribute : PresenterAttribute
	{
		/// <summary>
		/// Initializes a new attribute with the specified presenter type and key
		/// </summary>
		/// <param name="type">The type of presenter bound to the view class</param>
		/// <param name="key">The key of the presenter bound to the view class</param>
		public KeyedPresenterAttribute(Type type, object key) : base(type)
		{
			Contract.Requires(key != null);

			Key = key;
		}

		/// <summary>
		/// The key of the presenter bound to the view class
		/// </summary>
		public object Key { get; private set; }

		/// <summary>
		/// Gets a reference to the keyed presenter declaratively bound to the view
		/// </summary>
		/// <returns>The presenter declaratively bound to the view</returns>
		public override IPresenterReference GetReference()
		{
			return new KeyedPresenterReference(Type, Key);
		}
	}
}